package com.tingyuge.io.sqlSession;

import com.tingyuge.config.XMLConfigBuilder;
import com.tingyuge.io.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author xiaodao
 * @version 1.0
 * @date 2021/6/2
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream inputStream) throws DocumentException, PropertyVetoException {
        //使用dom4j 解析配置文件,将解析的内容封装到configuration中.
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);
        //2.创建SqlSessionFactory 对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return defaultSqlSessionFactory;
    }
}
